//特殊按钮类型
var ClubGroupBtn_All = -1;      //全部分组
var ClubGroupBtn_noGroup = -2;  //未分组
var ClubGroupBtn_AddGroup = -3; //增加分组
var ClubGroupSelectEvent = 'groupSelectEvent';
var ClubGroupItem = Item.extend({
    _ccsFileName: res.ClubGroupItem_json,
    _type: null,     //当前分组界面 打开类型
    _btnDatas: [],  //按钮数据
    initItem: function (data, type) {
        this._btnDatas = data;
        this._initBtnView();
        this._type = type;
        TouchUtil.setOnclickListener(this._nodeList['btn0'], this._clickBtn.bind(this), {swallowTouches: false});
        TouchUtil.setOnclickListener(this._nodeList['btn1'], this._clickBtn.bind(this), {swallowTouches: false});
        TouchUtil.setOnclickListener(this._nodeList['btn2'], this._clickBtn.bind(this), {swallowTouches: false});
    },

    _initBtnView: function () {
        for (var i = 0; i < 3; i++) {
            var btn = this._nodeList['btn' + i];
            btn.index = i;
            if (this._btnDatas[i] == undefined) {
                btn.setVisible(false);
                continue;
            }
            btn.setVisible(true);
            this._nodeList['btn' + i + '.label'].setString(this._getBtnLabelContent(this._btnDatas[i]));
            //如果type等于-3的话说明是增加分组按钮 需要特殊按钮颜色
            if (this._btnDatas[i]['type'] == -3) {
                this._nodeList['btn' + i].setTexture(res.btn_addGroup);
                this._nodeList['btn' + i + '.label'].setString('');
            }
        }
    },

    /**
     * 获得按钮上显示的文字内容
     * @param data
     * @private
     */
    _getBtnLabelContent: function (data) {
        if (!data['type']) {
            return data['name'];
        }
        if (data['type'] == -1) {
            return '全部分组';
        }
        if (data['type'] == -2) {
            return '未分组';
        }
        if (data['type'] == -3) {
            return '增加分组';
        }
        return '分组';
    },

    _clickBtn: function (target) {
        eventManager.dispatchEvent('groupSelectEvent', this._btnDatas[target.index], this._type);
    }
});